#ifndef _MAIN_H_
#define _MAIN_H_


#ifdef __ICCARM__
	#include <ST\iostm32f051x8.h>
	void WriteOut(const char * Str);
	#define _ASSERTE() 
#else
	#include <stdio.h>
	#include <crtdbg.h>
	#define WriteOut printf
#endif

#define PLLMUL 4 // SYS_CLOCK = 4MHz * (2 + PLLMUL)
#define SYS_CLOCK  (4000000 * (2 + (PLLMUL))) // 24MHz
#define HPRE 0xA // HCLK = SYS_CLOCK / 8 = 1.5MHz
#define HCLK ((HPRE) > 0x7 ? ((SYS_CLOCK) >> ((HPRE) - ((HPRE) < 0xC ? 0x7 : 0x6))) : SYS_CLOCK)
#define PPRE 4 // PCLK = HCLK / 2 = 750KHz
#define PCLK ((PPRE) > 3 ? (HCLK) >> ((PPRE) - 3) : (HCLK))
#define CK_INT ((PPRE) > 3 ? (PCLK) * 2 : (PCLK))
#define TIM_CLOCK CK_INT
#define SPIBR 1 // SPI boud rate = PCLK / 8 ~ 100KBoud

#define uSTEP 16
#define STEP_RES 100// 100 step/mm
#define uSTEP_RES (uSTEP * STEP_RES)
#define minV 3  // mm/s
#define maxV 15

#define QUEUE_SIZE 256
#define TIMER_DATA_SIZE 32
#define RX_SIZE 1024
#define CMD_MAX 5
#define SM_COUNT 3

typedef unsigned long DWORD;
typedef unsigned long long QWORD;
typedef unsigned char BYTE;

#endif